package com.larry.spark.wc

import org.apache.spark.{SparkConf, SparkContext}

object Spark01_WordCount_Env {

  def main(args: Array[String]): Unit = {
    //TODO  使用spark

    val conf = new SparkConf().setMaster("local").setAppName("WordCount")
    val sc = new SparkContext(conf)

    val lines = sc.textFile("C:\\Users\\larry\\IdeaProjects\\scala\\spark\\src\\main\\resources\\word.txt")

    //分词
    val words = lines.flatMap(_.split(" "))
    //分组
    val wordGroup = words.groupBy(word => word)

    //统计
    val wordcount = wordGroup.mapValues(_.size)

    wordcount.collect().foreach(println)

    sc.stop()
  }


}
